home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 2 / ETO Development Tools 2.iso / Tools - Objects / MacApp / MacApp CD Release / MacApp 2.0.1 (Many Libraries) / Libraries / UDebug.a < prev    next >
Encoding:
Text File  |  1990-10-25  |  9.1 KB  |  309 lines  |  [TEXT/MPS ]

  1. ; Copyright © 1987-1990 by Apple Computer, Inc.  All rights reserved.
  2. ; UDebug assembly language routines
  3.  
  4.                 Blanks        On
  5.                 String        AsIs
  6.                 Case        On
  7.  
  8.                 Print        Off
  9.                 Include     'Macros.a'
  10.  
  11.                 Include        'IntEnv.a'
  12.  
  13.                 LOAD            'ProgStrucMacs.d'
  14.                 LOAD            'FlowCtlMacs.d'
  15.                 Print        On
  16.  
  17. ;---------------------------------------------------------------------------------------------------
  18. DebugGlobals     Record
  19.                 Export        pCanEnterDebugger, pUDebugInitialized, pSegTable
  20. pCanEnterDebugger DC.W        0                    ; Boolean: Debugger can be entered
  21. pUDebugInitialized DC.W        0                    ; Boolean: if Trace unit is inited
  22. pSegTable        DC.L        0                    ; HandleListHandle
  23.                 EndR                            ; Too bad Pascal doesn't have initialization
  24.  
  25.     IF qDebug then
  26.                 Import        DEBUGEXCEPTION        ; in UDebug
  27.  
  28. XDEBUGSYSERROR    Proc        Export                ; SysError(errorCode: integer) [arg is in Reg D0]
  29.                 Clr.L        -(SP)                ; leave room for DEBUGException to leave our continuation address
  30.                 MoveM.L     A0-A7/D0-D7,-(SP)    ; save registers
  31.                 Move.W        D0,-(SP)            ; push errorCode On stack to call Pascal
  32.                 Jsr         DEBUGEXCEPTION        ; call a Pascal routine
  33.                 MoveM.L     (SP)+,A0-A7/D0-D7    ; restore registers
  34.                 Rts                             ; leave things just as they were when we started, And go to debugger
  35.                 EndProc
  36.  
  37.                 Seg         'MADebugger'                ; MUST BE IN Main SEGMENT
  38. XDEBUGBUSERROR    Proc        Export                ; Bus error
  39.                 Clr.L        -(SP)                ; leave room for DEBUGEXCEPTION to leave our continuation address
  40.                 MoveM.L     A0-A7/D0-D7,-(SP)    ; save registers
  41.                 Move.W        #902,-(SP)            ; push errorCode On stack to call Pascal
  42.                 Jsr         DEBUGEXCEPTION        ; call a Pascal routine
  43.                 MoveM.L     (SP)+,A0-A7/D0-D7    ; restore registers
  44.                 Rts                             ; leave things just as they were when we started, And go to debugger
  45.                 EndProc
  46.  
  47.                 Seg         'MADebugger'                ; MUST BE IN Main SEGMENT
  48. XDEBUGADDRERROR    Proc        Export                ; Address error
  49.                 Clr.L        -(SP)                ; leave room for DEBUGEXCEPTION to leave our continuation address
  50.                 MoveM.L     A0-A7/D0-D7,-(SP)    ; save registers
  51.                 Move.W        #903,-(SP)            ; push errorCode On stack to call Pascal
  52.                 Jsr         DEBUGEXCEPTION        ; call a Pascal routine
  53.                 MoveM.L     (SP)+,A0-A7/D0-D7    ; restore registers
  54.                 Rts                             ; leave things just as they were when we started, And go to debugger
  55.                 EndProc
  56.  
  57.                 Seg         'MADebugger'                ; MUST BE IN Main SEGMENT
  58. XDEBUGILLINST     Proc        Export                ; Illegal Instruction
  59.                 Clr.L        -(SP)                ; leave room for DEBUGEXCEPTION to leave our continuation address
  60.                 MoveM.L     A0-A7/D0-D7,-(SP)    ; save registers
  61.                 Move.W        #904,-(SP)            ; push errorCode On stack to call Pascal
  62.                 Jsr         DEBUGEXCEPTION        ; call a Pascal routine
  63.                 MoveM.L     (SP)+,A0-A7/D0-D7    ; restore registers
  64.                 Rts                             ; leave things just as they were when we started, And go to debugger
  65.                 EndProc
  66.  
  67.                 Seg         'MADebugger'                ; MUST BE IN Main SEGMENT
  68. XDEBUGZERODIV     Proc        Export                ; Zero Divide
  69.                 Clr.L        -(SP)                ; leave room for DEBUGEXCEPTION to leave our continuation address
  70.                 MoveM.L     A0-A7/D0-D7,-(SP)    ; save registers
  71.                 Move.W        #905,-(SP)            ; push errorCode On stack to call Pascal
  72.                 Jsr         DEBUGEXCEPTION        ; call a Pascal routine
  73.                 MoveM.L     (SP)+,A0-A7/D0-D7    ; restore registers
  74.                 Rts                             ; leave things just as they were when we started, And go to debugger
  75.                 EndProc
  76.  
  77.                 Seg         'MADebugger'                ; MUST BE IN Main SEGMENT
  78. XDEBUGCHECK        Proc        Export                ; Chk
  79.                 Clr.L        -(SP)                ; leave room for DEBUGEXCEPTION to leave our continuation address
  80.                 MoveM.L     A0-A7/D0-D7,-(SP)    ; save registers
  81.                 Move.W        #906,-(SP)            ; push errorCode On stack to call Pascal
  82.                 Jsr         DEBUGEXCEPTION        ; call a Pascal routine
  83.                 MoveM.L     (SP)+,A0-A7/D0-D7    ; restore registers
  84.                 Rts                             ; leave things just as they were when we started, And go to debugger
  85.                 EndProc
  86.  
  87.                 Seg         'MADebugger'                ; MUST BE IN Main SEGMENT
  88. XDEBUGOVERFLOW    Proc        Export                ; TrapV
  89.                 Clr.L        -(SP)                ; leave room for DEBUGEXCEPTION to leave our continuation address
  90.                 MoveM.L     A0-A7/D0-D7,-(SP)    ; save registers
  91.                 Move.W        #907,-(SP)            ; push errorCode On stack to call Pascal
  92.                 Jsr         DEBUGEXCEPTION        ; call a Pascal routine
  93.                 MoveM.L     (SP)+,A0-A7/D0-D7    ; restore registers
  94.                 Rts                             ; leave things just as they were when we started, And go to debugger
  95.                 EndProc
  96.  
  97.                 Seg         'MADebugger'                ; MUST BE IN Main SEGMENT
  98. XDEBUGLINEF        Proc        Export                ; Line 1111 traps
  99.                 Clr.L        -(SP)                ; leave room for DEBUGEXCEPTION to leave our continuation address
  100.                 MoveM.L     A0-A7/D0-D7,-(SP)    ; save registers
  101.                 Move.W        #911,-(SP)            ; push errorCode On stack to call Pascal
  102.                 Jsr         DEBUGEXCEPTION        ; call a Pascal routine
  103.                 MoveM.L     (SP)+,A0-A7/D0-D7    ; restore registers
  104.                 Rts                             ; leave things just as they were when we started, And go to debugger
  105.                 EndProc
  106.  
  107. ;                Seg         'MADebugger'                ; MUST BE IN Main SEGMENT
  108. ;                .Proc         XDEBUGNMI            ; NMI (level 7)
  109. ;                Clr.L         -(SP)                ; leave room for DEBUGEXCEPTION to leave our continuation address
  110. ;                MoveM.L     A0-A7/D0-D7,-(SP)    ; save registers
  111. ;                Move.W        #900,-(SP)            ; push errorCode On stack to call Pascal
  112. ;                Jsr         DEBUGEXCEPTION        ; call a Pascal routine
  113. ;                MoveM.L     (SP)+,A0-A7/D0-D7    ; restore registers
  114. ;                Rts                             ; leave things just as they were when we started, And go to debugger
  115. ;                EndProc
  116.  
  117.     Endif
  118.  
  119.  
  120. ;---------------------------------------------------------------------------------------------------
  121. DevGlobals     Record
  122.                 Export        pDebugWindow, pFileName
  123. pDebugWindow    DC.L    0            ; Reference to debug window. Contained here so it can be
  124.                                     ; initialized to nil
  125. pPutProc        DC.L    0            ; Address of the PASCAL Proc to Handle WriteLn requests
  126.                                     ; Procedure DEVPUTTEXT(textBuf: Ptr, byteCount: longint);
  127. pGetProc        DC.L    0            ; Address of the PASCAL Proc to Handle Read requests
  128.                                     ; Function DEVGETTEXT(textBuf: Ptr, byteCount: longint): longint;
  129.  
  130. pFileName        DCB.B    256,0        ; FileName to intercept for console
  131.                 EndR
  132.  
  133. ;-----------------------------------------------------------------------------------
  134. ;int DevFAccess(fName, cmd, arg)
  135. ;    char    *fName;
  136. ;    int     cmd;
  137. ;    char    *arg;
  138. ;{
  139. ;# define IgnoreCase         false
  140. ;# define DiacritSens     true
  141. ;
  142. ;/*
  143. ;    if ((equalstring(fName, pFileName, false, true)))
  144. ;*/
  145. ;        switch (cmd) {
  146. ;            default:
  147. ;                return(-1);
  148. ;            case F_OPEN:
  149. ;                return(0);
  150. ;        }
  151. ;/*
  152. ;    else
  153. ;        return(-1);
  154. ;*/
  155. ;}
  156. F_OPEN        EQU         (('d'<<8)|00)        ; for internal use only. Use only as directed.
  157.             Seg         'Main'
  158. EXPORT FUNCTION DevFAccess(fName:L, cmd:L, arg:L):L,C
  159.     BEGIN    SAVE=D2/D3,WITH=DevGlobals
  160.             Import        EQUALSTRING, P2CSTRPROC, C2PSTRPROC        ; library routines
  161.             MOVE.L    cmd(FP),D3
  162.             Call    C2PSTRPROC(fName(FP):L);
  163.             LEA        pFileName,A0
  164.             Call    EQUALSTRING:B(fName(FP):L, A0:L, #0:B, #1:B),D2
  165.             Call    P2CSTRPROC(fName(FP):L);
  166.             IF# D2 NE.B #0 THEN.S
  167.                 Switch# D3
  168.                 
  169.                 Case#.S    F_OPEN
  170.                         MOVEQ        #0,D0
  171.                         Leave#.S
  172.                 Default#
  173.                         MOVEQ        #-1,D0
  174.             
  175.                 EndS#            
  176.             ELSE#.S
  177.                 MOVEQ        #-1,D0
  178.             ENDIF#            
  179.  
  180.             RETURN     
  181.             EndF
  182.  
  183.  
  184. ;-----------------------------------------------------------------------------------
  185. ;int DevClose()
  186. ;{
  187. ;    return(0);
  188. ;}
  189.  
  190.             Seg         'Main'
  191. EXPORT FUNCTION DevClose:L,C
  192.         BEGIN
  193.             MOVEQ       #0,D0
  194.             Return
  195.             EndF
  196.  
  197.  
  198. ;-----------------------------------------------------------------------------------
  199.  
  200.             Seg         'Main'
  201. EXPORT FUNCTION SETGETPROC(theGetProc:L):L
  202.         BEGIN    with=DevGlobals
  203.             MOVE.L        pGetProc,SETGETPROC(FP)
  204.             MOVE.L        theGetProc(FP), pGetProc
  205.             Return
  206.             EndF
  207.  
  208. ;-----------------------------------------------------------------------------------
  209.  
  210.             Seg         'Main'
  211. EXPORT FUNCTION SETPUTPROC(thePutProc:L):L
  212.         BEGIN    with=DevGlobals
  213.             MOVE.L        pPutProc,SETPUTPROC(FP)
  214.             MOVE.L        thePutProc(FP), pPutProc
  215.             Return
  216.             EndF
  217.  
  218.  
  219. ;-----------------------------------------------------------------------------------
  220. ;int DevRead(iop)
  221. ;    IOPort    *iop;
  222. ;{
  223. ;    int     bytesRead;
  224. ;
  225. ;    bytesRead = DevReadLn(iop->inQ.bufp, iop->inQ.count);
  226. ;    iop->inQ.bufp += bytesRead;
  227. ;    iop->inQ.count -= bytesRead;
  228. ;    return(0);
  229. ;}
  230.  
  231.             Seg         'Main'
  232. EXPORT FUNCTION DevRead(iop:L):L,C
  233.     BEGIN with=DevGlobals,SAVE=D2/A2
  234.  
  235.             MOVE.L        iop(FP),A2
  236.  
  237. ;            CALL        (pGetProc):L($10(A2):L,$0E(A2):W),D0
  238.             MOVE.L        pGetProc, A0
  239.             CLR.L        -(SP)                ;make room for function result
  240.             MOVE.L        $10(A2), -(SP)
  241.             MOVE.W        $0E(A2), -(SP)
  242.             JSR            (A0)
  243.             MOVE.L        (SP)+,D0
  244.  
  245.             ADD.L        D0,$10(A2)            ;add it to bufp
  246.             SUB.L        D0,$0C(A2)             ;sub it from count
  247.             MOVEQ        #0,D0                ;Return value
  248.             RETURN
  249.             ENDF
  250.  
  251.  
  252. ;-----------------------------------------------------------------------------------
  253. ;int DevWrite(iop)
  254. ;    IOPort    *iop;
  255. ;{
  256. ;    DevAddText(iop->inQ.bufp, iop->inQ.count);
  257. ;    
  258. ;    return(0);
  259. ;}
  260.  
  261.             Seg         'Main'
  262. EXPORT FUNCTION DevWrite(iop:L):L,C
  263.     BEGIN with=DevGlobals,SAVE=D2/A2
  264.  
  265.             MOVE.L        iop(FP),A2
  266.  
  267. ;            CALL        (pPutProc)($10(A2):L,$0E(A2):W)
  268.             MOVE.L        pPutProc, A0
  269.             MOVE.L        $10(A2), -(SP)
  270.             MOVE.W        $0E(A2), -(SP)
  271.             JSR            (A0)
  272.  
  273.             CLR.L        $0C(A2)
  274.             MOVEQ        #0,D0                ;Return Value
  275.             RETURN
  276.             ENDF
  277.  
  278. ;-----------------------------------------------------------------------------------
  279. ;int DevIoctl(iop, cmd, arg)
  280. ;    IOPort    *iop;
  281. ;    int     cmd;
  282. ;    char    *arg;
  283. ;{
  284. ;    switch (cmd) {
  285. ;        case FIOINTERACTIVE:
  286. ;        case TIOFLUSH:
  287. ;            return(0);
  288. ;        default:
  289. ;            return(-1);
  290. ;    }
  291. ;}
  292.             Seg         'Main'
  293. EXPORT FUNCTION DevIoctl(iop:L, cmd:L, arg:L):L,C
  294.     BEGIN
  295.     Switch#    cmd(FP)
  296.             
  297.     Case#.S    FIOINTERACTIVE,TIOFLUSH
  298.             MOVEQ        #0,D0                ;Return Value
  299.             Leave#.S
  300.  
  301.     Default#
  302.             MOVEQ        #-1,D0                ;Return Value
  303.     EndS#
  304.  
  305.             RETURN     
  306.             EndF
  307.         
  308.                 End
  309.